﻿using System;
using System.Linq.Expressions;

namespace 历史记录.Helper
{
    public static class ExpressionEx
    {
        public static Expression<Func<T, bool>> AndAlso<T>(this Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
        {
            if (left == null) return right;
            else if (right == null) return left;
            var P = Expression.Parameter(typeof(T), "data");
            var vis = new MyExpressionVisitor(P);
            Expression Bodyexp1 = vis.Visit(left.Body);
            Expression Bodyexp2 = vis.Visit(right.Body);
            Expression exp3 = Expression.AndAlso(Bodyexp1, Bodyexp2);
            return Expression.Lambda<Func<T, bool>>(exp3, P);
        }
    }
}